
// +----------------------------------------------------------------------
// | ajax 请求封装
// +----------------------------------------------------------------------
// | Author: 辰风沐阳 <23426945@qq.com>
// +----------------------------------------------------------------------

layui.define(['jquery'], function (exports) {

    var n = "color:#FF5722;font-weight:bolder;font-size:12px"
    console.info('%c' + "ajax请求封装模块已就绪 -- 辰风沐阳", n);

    var $ = layui.jquery;
    var obj = {
        ajax: function (url, type, dataType, data, callback) {

            console.log('------------------------------------------------------------')

            console.log('请求地址: ', url)
            console.log('请求类型: ', type.toLocaleUpperCase())
            console.log('请求参数: ', data)
            $.ajax({
                url: url,
                type: type,
                dataType: dataType,
                data: data,
                success: callback
            });
        },
        log: function (data) {
            console.log('响应结果: ', data)

            console.log('------------------------------------------------------------')
        },
        url: function (url, param) {
            var link = ''
            for (let key in param) {
                link += key + '=' + param[key] + '&'
            }
            link = link.substring(0, link.length - 1);
            url += (/\?/.test(url) ? '&' : '?') + link
            return url;
        },
        getIds: (checkData) => {
            var ids = [];
            for (var v of checkData) ids.push(v.id);
            return ids;
        }
    };
    // 输出接口
    exports('request', obj);
});